﻿using KseCms.Application.Services;
using System.Security.Claims;

namespace KseCms.Application
{
    [Authorize]
    public class ShoppingCartAppService : IDynamicApiController
    {
        private readonly IShoppingCartService _ShoppingCartService;
        public ShoppingCartAppService(IShoppingCartService ShoppingCartService)
        {
            _ShoppingCartService = ShoppingCartService;
        }

        public async Task<PagedList<ShoppingCartDto>> GetPageList([FromQuery]PageDto page)
        {
            return await _ShoppingCartService.GetList(page);
        }

        public async Task<ShoppingCartDto> Get(string id)
        {
            return await _ShoppingCartService.GetById(id);
        }

        public async Task<object> Create(ShoppingCartDto shoppingCart)
        {
            shoppingCart.UserId = App.User?.FindFirstValue("UserId");

            await _ShoppingCartService.Create(shoppingCart);

            return Results.Ok();
        }

        public async Task<object> Delete(string id)
        {
            await _ShoppingCartService.Delete(id);

            return Results.Ok();
        }

        public async Task<object> Update(ShoppingCartDto shoppingCart)
        {
            await _ShoppingCartService.Update(shoppingCart);

            return Results.Ok();
        }
    }
}
